package com.scott.itcast.timer.lesson05;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 定时器  炸弹里面还有炸弹 子母弹
 */
public class TraditionalTimer {
	
	private static int counter =0;
	
	@SuppressWarnings("deprecation")
	public static void main(String[] args) {
		
		
		//MyTimerTask 是1个任务类
		class MyTimerTask extends TimerTask{
			@Override
			public void run() {
				counter =(counter+1)%2;
				System.out.println("bombing...");
				new Timer().schedule(new MyTimerTask(), counter==1?4000:2000);
			}
			
		}
		
		
		new Timer().schedule(new MyTimerTask(), 2000);
		
		
		
		while(true){
			System.out.println(new Date().getSeconds());
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}
